<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" />
		<title>投放明细</title>
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
		<meta http-equiv="description" content="This is my page" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link rel="stylesheet" type="text/css" 
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="<%=path%>/js/form.js"></script>
		<script type="text/javascript" src="<%=path%>/js/public.js"></script>
		<script type="text/javascript">
			function setMediumStatus(v_mediumStatus)
			{
			    if(v_mediumStatus != null && v_mediumStatus != '' && v_mediumStatus != 'null')
				{
				   $("#mediumStatus").hide();
				   $("#mediumStatus").val(v_mediumStatus);
				   $("#showMediumStatus").val($("#mediumStatus").find("option:selected").text());
				   $("#showMediumStatus").show();
				}
				else
				{
				   $("#mediumStatus").show();
				   $("#mediumStatus").val('');
				   $("#showMediumStatus").hide();
				}
			}
			
			$(function() {
				$("#showMediumStatus").hide();
				
				// 项目弹框设置
				$("#ajaxGetProjectDialog").dialog({
					autoOpen: false,
					modal: true,
					width: 400,
					height: 410,
					title: "项目选择",
					//resizable: false,
					//show: "explode",
					//hide: "explode"
					show: "blind",
					hide:"slide"
				});
				// 项目选择
				$("#projectName").click(function(){
					$("#keyword").val("");
					$.post("ajaxGetProject.action", null, 
						function(result){
							$("#ajaxGetProjectDialog select").empty();
							var ajaxProjects = result.ajaxProjects;
							if(ajaxProjects == null || ajaxProjects.length <= 0){
								alert("没有可选项目！");
							}else{
								for(i=0;i<ajaxProjects.length;i++){
									$("#ajaxGetProjectDialog select").append("<option class=\""+ajaxProjects[i].proCurStatus+"\" value=\""+ajaxProjects[i].projectId+"\" title=\""+ajaxProjects[i].projectName+"\">"+ajaxProjects[i].projectName+"</option>");
								}
								$("#ajaxGetProjectDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetProjectDialog select").dblclick(function(){
									$("#projectID").val($(this).val());
									$("#projectName").val($(this).find("option:selected").text());
									var v_mediumStatus = $(this).find("option:selected").attr("class");
									setMediumStatus(v_mediumStatus);
									$("#ajaxGetProjectDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetProjectDialog").dialog("open");
							}
						}, "json");
					return false;
				});
				
				// 媒体弹框设置
				$("#ajaxGetMediaDialog").dialog({
					autoOpen: false,
					modal: true,
					width: 400,
					height: 410,
					title: "媒体选择",
					show: "blind",
					hide:"slide"
				});
				// 媒体选择
				$("#mediaName").click(function(){
					$("#keyword").val("");
					$.post("ajaxGetMedia.action", null, 
						function(result){
							$("#ajaxGetMediaDialog select").empty();
							var ajaxMedias = result.ajaxMedias;
							if(ajaxMedias == null || ajaxMedias.length <= 0){
								alert("没有可选媒体！");
							}else{
								for(i=0;i<ajaxMedias.length;i++){
									$("#ajaxGetMediaDialog select").append("<option value=\""+ajaxMedias[i].mediaID+"\" title=\""+ajaxMedias[i].mediaName+"\">"+ajaxMedias[i].mediaName+"</option>");
								}
								$("#ajaxGetMediaDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediaDialog select").dblclick(function(){
									$("#mediaID").val($(this).val());
									$("#mediaName").val($(this).find("option:selected").text());
									$("#mediumID").val('');
									$("#mediumName").val('');
									$("#ajaxGetMediaDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediaDialog").dialog("open");
							}
						}, "json");
					return false;
				});
				/*
				// 二级联动
				$("#mediaID").change(function(){
					var mediaID = $(this).val()
					if(mediaID != ""){
						$.post("ajaxGetMedium.action?projectMedium.mediaID="+mediaID, null, function(result){
							$("#mediumID").html("<option value=\"\">--投放刊例--</option>");
							var ajaxMediums = result.ajaxMediums;
							if(ajaxMediums != null){
								for(i=0;i<ajaxMediums.length;i++){
									var content  = "刊例名称："+ ajaxMediums[i].mediumName +"&#13;";
										content += "年度："+ ajaxMediums[i].contractYear +"&#13;";
										content += "刊例能力："+ ajaxMediums[i].mediumAbility +"&#13;";
										content += "刊例价(元)："+ ajaxMediums[i].mediumPrice +"&#13;";
									$("#mediumID").append("<option value=\""+ajaxMediums[i].id+"\" title=\""+content+"\" >"+ajaxMediums[i].mediumName+"</option>");
								}
							}
						}, "json");
					}else{
						$("#mediumID").html("<option value=\"\">--投放刊例--</option>");
					}
				});*/
				//
				$("#basicSubmitButton").click(function(){
					if($("#projectName").val() == ""){
						alert("项目名称未选择！");
					}else if($("#arrangeTime").val() == ""){
						alert("排期时间不能为空！");
					}else if($("#mediaID").val() == ""){
						alert("投放媒体未选择！");
					}else if($("#mediumID").val() == ""){
						alert("投放刊例未选择！");
					}else if($("#mediumOrientDiscount").val() == ""){
						alert("定向折扣不能为空！");
					}else if($("#mediumStatus").val() == ""){
						alert("资源占用状态未选择！");
					}else{
						formSubmit('basicForm', 'initBasicInfo', 'insertBasicInfo.action?isInsertFlag=1', showResult);
					}
				});
				//
				$("#mediumOrientDiscount").blur(function(){
					var mediumOrientDiscount = $(this).val();
					var reg = /^\d*?$/;
					//if(reg.test(mediumOrientDiscount)){
					if(isFloat(mediumOrientDiscount)){
						if(mediumOrientDiscount > 100 || mediumOrientDiscount < 0){
							alert("定向折扣必须为0~100以内数字！");
							$(this).val("");
						}
					}else{
						alert("定向折扣必须为0~100以内数字！");
						$(this).val("");
					}
				});
				
				//判断是否为浮点数
				function isFloat(oNum) 
				{ 
					 if(oNum == 0)
					 {
					    return true;
					 }
					 if(!oNum) return false;
					 var strP=/^\d+(\.\d+)?$/;
					 if(!strP.test(oNum)) return false;
					 try{
					 	if(parseFloat(oNum)!=oNum) return false;
					 }catch(ex){
					   return false;
					 }
					 return true;
				}
				
				$("#keywordSearch").click(function(){
					$.post("ajaxGetProject.action", {keyword:$("#keyword").val()}, 
						function(result){
							$("#ajaxGetProjectDialog select").empty();
							var ajaxProjects = result.ajaxProjects;
							if(ajaxProjects == null || ajaxProjects.length <= 0){
								alert("没有可选项目！");
							}else{
								for(i=0;i<ajaxProjects.length;i++){
									$("#ajaxGetProjectDialog select").append("<option class=\""+ajaxProjects[i].proCurStatus+"\" value=\""+ajaxProjects[i].projectId+"\" title=\""+ajaxProjects[i].projectName+"\">"+ajaxProjects[i].projectName+"</option>");
								}
								$("#ajaxGetProjectDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetProjectDialog select").dblclick(function(){
									$("#projectID").val($(this).val());
									$("#projectName").val($(this).find("option:selected").text());
									var v_mediumStatus = $(this).find("option:selected").attr("class");
									setMediumStatus(v_mediumStatus);
									$("#ajaxGetProjectDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetProjectDialog").dialog("open");
							}
						}, "json");
				});
				
				//
				$("#keywordReset").click(function(){
					$("#keyword").val("");
					$.post("ajaxGetProject.action", null, 
						function(result){
							$("#ajaxGetProjectDialog select").empty();
							var ajaxProjects = result.ajaxProjects;
							if(ajaxProjects == null || ajaxProjects.length <= 0){
								alert("没有可选项目！");
							}else{
								for(i=0;i<ajaxProjects.length;i++){
									$("#ajaxGetProjectDialog select").append("<option class=\""+ajaxProjects[i].proCurStatus+"\" value=\""+ajaxProjects[i].projectId+"\" title=\""+ajaxProjects[i].projectName+"\">"+ajaxProjects[i].projectName+"</option>");
								}
								$("#ajaxGetProjectDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetProjectDialog select").dblclick(function(){
									$("#projectID").val($(this).val());
									$("#projectName").val($(this).find("option:selected").text());
									var v_mediumStatus = $(this).find("option:selected").attr("class");
									setMediumStatus(v_mediumStatus);
									$("#ajaxGetProjectDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetProjectDialog").dialog("open");
							}
						}, "json");
				});
				//
				$("#keyword").keydown(function(event){
					if(event.which == 13){
						$("#keywordSearch").click();
					}
				});
				
				// 媒体查询
				$("#mediaKeywordSearch").click(function(){
					$.post("ajaxGetMedia.action", {keyword:$("#keywordMedia").val()}, 
						function(result){
							$("#ajaxGetMediaDialog select").empty();
							var ajaxMedias = result.ajaxMedias;
							if(ajaxMedias == null || ajaxMedias.length <= 0){
								alert("没有可选媒体！");
							}else{
								for(i=0;i<ajaxMedias.length;i++){
									$("#ajaxGetMediaDialog select").append("<option value=\""+ajaxMedias[i].mediaID+"\" title=\""+ajaxMedias[i].mediaName+"\">"+ajaxMedias[i].mediaName+"</option>");
								}
								$("#ajaxGetMediaDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediaDialog select").dblclick(function(){
									$("#mediaID").val($(this).val());
									$("#mediaName").val($(this).find("option:selected").text());
									$("#ajaxGetMediaDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediaDialog").dialog("open");
							}
						}, "json");
				});
				
				// 媒体查询
				$("#mediaKeywordReset").click(function(){
					$("#keywordMedia").val("");
					$.post("ajaxGetMedia.action", null, 
						function(result){
							$("#ajaxGetMediaDialog select").empty();
							var ajaxMedias = result.ajaxMedias;
							if(ajaxMedias == null || ajaxMedias.length <= 0){
								alert("没有可选媒体！");
							}else{
								for(i=0;i<ajaxMedias.length;i++){
									$("#ajaxGetMediaDialog select").append("<option value=\""+ajaxMedias[i].mediaID+"\" title=\""+ajaxMedias[i].mediaName+"\">"+ajaxMedias[i].mediaName+"</option>");
								}
								$("#ajaxGetMediaDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediaDialog select").dblclick(function(){
									$("#mediaID").val($(this).val());
									$("#mediaName").val($(this).find("option:selected").text());
									$("#ajaxGetMediaDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediaDialog").dialog("open");
							}
						}, "json");
				});
				
				// 刊例弹框设置
				$("#ajaxGetMediumDialog").dialog({
					autoOpen: false,
					modal: true,
					width: 400,
					height: 410,
					title: "刊例选择",
					show: "blind",
					hide:"slide"
				});
				// 刊例选择
				$("#mediumName").click(function(){
					$("#keywordMedium").val("");
					var mediaID = $("#mediaID").val()
					if(mediaID == null || mediaID == '')
					{
					   alert("请先选择媒体！");
					   return false;
					}
					$.post("ajaxGetMedium.action", {'projectMedium.mediaID':mediaID}, 
						function(result){
							$("#ajaxGetMediumDialog select").empty();
							var ajaxMediums = result.ajaxMediums;
							if(ajaxMediums == null || ajaxMediums.length <= 0){
								alert("没有可选刊例！");
							}else{
								for(i=0;i<ajaxMediums.length;i++){
									var content  = ajaxMediums[i].mediumName;
									if(ajaxMediums[i].mediumPage != null && ajaxMediums[i].mediumPage != '')
									{
									   content += "_" + ajaxMediums[i].mediumPage;
									}
									
									if(ajaxMediums[i].mediumColumn != null && ajaxMediums[i].mediumColumn != '')
									{
									   content += "_" + ajaxMediums[i].mediumColumn;
									}
									
									$("#ajaxGetMediumDialog select").append("<option value=\""+ajaxMediums[i].id+"\" title=\""+content+"\">"+content+"</option>");
								}
								$("#ajaxGetMediumDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediumDialog select").dblclick(function(){
									$("#mediumID").val($(this).val());
									$("#mediumName").val($(this).find("option:selected").text());
									$("#ajaxGetMediumDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediumDialog").dialog("open");
							}
						}, "json");
					return false;
				});
				// 刊例查询
				$("#mediumKeywordSearch").click(function(){
					var mediaID = $("#mediaID").val()
					$.post("ajaxGetMedium.action", {keyword:$("#keywordMedium").val(),'projectMedium.mediaID':mediaID}, 
						function(result){
							$("#ajaxGetMediumDialog select").empty();
							var ajaxMediums = result.ajaxMediums;
							if(ajaxMediums == null || ajaxMediums.length <= 0){
								alert("没有可选刊例！");
							}else{
								for(i=0;i<ajaxMediums.length;i++){
									var content  = ajaxMediums[i].mediumName;
									if(ajaxMediums[i].mediumPage != null && ajaxMediums[i].mediumPage != '')
									{
									   content += "_" + ajaxMediums[i].mediumPage;
									}
									
									if(ajaxMediums[i].mediumColumn != null && ajaxMediums[i].mediumColumn != '')
									{
									   content += "_" + ajaxMediums[i].mediumColumn;
									}
									
									$("#ajaxGetMediumDialog select").append("<option value=\""+ajaxMediums[i].id+"\" title=\""+content+"\">"+content+"</option>");
								}
								$("#ajaxGetMediumDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediumDialog select").dblclick(function(){
									$("#mediumID").val($(this).val());
									$("#mediumName").val($(this).find("option:selected").text());
									$("#ajaxGetMediumDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediumDialog").dialog("open");
							}
						}, "json");
				});
				// 刊例查询
				$("#mediumKeywordReset").click(function(){
					$("#keywordMedium").val("");
					var mediaID = $("#mediaID").val()
					$.post("ajaxGetMedium.action", {'projectMedium.mediaID':mediaID}, 
						function(result){
							$("#ajaxGetMediumDialog select").empty();
							var ajaxMediums = result.ajaxMediums;
							if(ajaxMediums == null || ajaxMediums.length <= 0){
								alert("没有可选刊例！");
							}else{
								for(i=0;i<ajaxMediums.length;i++){
									var content  = ajaxMediums[i].mediumName;
									if(ajaxMediums[i].mediumPage != null && ajaxMediums[i].mediumPage != '')
									{
									   content += "_" + ajaxMediums[i].mediumPage;
									}
									
									if(ajaxMediums[i].mediumColumn != null && ajaxMediums[i].mediumColumn != '')
									{
									   content += "_" + ajaxMediums[i].mediumColumn;
									}
									
									$("#ajaxGetMediumDialog select").append("<option value=\""+ajaxMediums[i].id+"\" title=\""+content+"\">"+content+"</option>");
								}
								$("#ajaxGetMediumDialog select").unbind("dblclick");
								//点击事件
								$("#ajaxGetMediumDialog select").dblclick(function(){
									$("#mediumID").val($(this).val());
									$("#mediumName").val($(this).find("option:selected").text());
									$("#ajaxGetMediumDialog").dialog("close");
								});
								//显示弹框
								$("#ajaxGetMediumDialog").dialog("open");
							}
						}, "json");
				});
				
			});
		</script>
	</head>

	<body>
		<input type="hidden" name="chkProMedID" id="chkProMedID"/>
		<form id="basicForm" method="post">
			<table class="table_add" style="width:100%;">
				<tr>
					<th style="width:150px;">项目名称：</th>
					<td style="width:225px;">
						<input id="projectName" type="text" class="text" style="width:225px;" readonly="readonly" />
						<input id="projectID" name="projectMedium.projectID" type="hidden" class="text" style="width:225px;" />
					</td>
					<th style="width:189px;">排期时间：</th>
					<td style="width: 465px;">
						<input id="arrangeTime" name="projectMedium.arrangeTime" type="text" class="text Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM'})" style="width:225px;" readonly="readonly" />
					</td>
					<td>
						<input id="basicSubmitButton" type="button" class="btn-title" value="保存" />
						&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" class="btn-title" value="取消" onclick="if(confirm('您确认取消本次操作？')){window.location.href = 'mediumCastDetailList.action';}" />
					</td>
				</tr>
				<tr>
					<th style="width:150px;">投放媒体：</th>
					<td style="width:225px;">
						<input id="mediaName" type="text" class="text" style="width:225px;" readonly="readonly" />
						<input id="mediaID" name="projectMedium.mediaID" type="hidden" class="text" style="width:225px;" />
					</td>
					<th style="width:189px;">投放刊例：</th>
					<td>
						<input id="mediumName" type="text" class="text" style="width:225px;" readonly="readonly" />
						<input id="mediumID" name="projectMedium.id_medium" type="hidden" class="text" style="width:225px;" />
					</td>
				</tr>
				<tr>
					<th style="width:150px;">定向折扣(%)：</th>
					<td style="width:225px;">
						<input id="mediumOrientDiscount" name="projectMedium.mediumOrientDiscount" type="text" class="text" style="width:225px;" value="100"/>
					</td>
					<th style="width:189px;">资源占用状态：</th>
					<td>
						<input type="text" class="text" style="width:225px;" disabled="disabled" id="showMediumStatus"/>
						<s:select id="mediumStatus" name="projectMedium.mediumStatus" cssStyle="width:227px;" 
						list="mediumStatusSelect" listKey="id" listValue="datavalue" headerKey="" headerValue="--资源占用状态--"></s:select>
					</td>
				</tr>
			</table>
		</form>
		<div id="ajaxGetProjectDialog" style="display: none;">
			<table width="0" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<input type="text" style="width: 250px" id="keyword"
							class="text" />
						&nbsp;
						<input id="keywordSearch" type="button" class="btn-title" value="搜索" />
						&nbsp;
						<input id="keywordReset" type="button" class="btn-title" value="重置" />
					</td>
				</tr>
				<tr>
					<td style="padding-top: 5px;">
						<select multiple="multiple"
							style="width: 100%; height: 335px; overflow:hidden;" >
						</select>
					</td>
				</tr>
			</table>
		</div>
		<div id="ajaxGetMediaDialog" style="display: block;">
			<table width="0" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<input type="text" style="width: 250px" id="keywordMedia"
							class="text" />
						&nbsp;
						<input id="mediaKeywordSearch" type="button" class="btn-title" value="搜索" />
						&nbsp;
						<input id="mediaKeywordReset" type="button" class="btn-title" value="重置" />
					</td>
				</tr>
				<tr>
					<td style="padding-top: 5px;">
						<select multiple="multiple"
							style="width: 100%; height: 335px; overflow:hidden;" >
						</select>
					</td>
				</tr>
			</table>
		</div>
		
		<div id="ajaxGetMediumDialog" style="display: block;">
			<table width="0" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<input type="text" style="width: 250px" id="keywordMedium"
							class="text" />
						&nbsp;
						<input id="mediumKeywordSearch" type="button" class="btn-title" value="搜索" />
						&nbsp;
						<input id="mediumKeywordReset" type="button" class="btn-title" value="重置" />
					</td>
				</tr>
				<tr>
					<td style="padding-top: 5px;">
						<select multiple="multiple"
							style="width: 100%; height: 335px; overflow:hidden;" >
						</select>
					</td>
				</tr>
			</table>
		</div>
	</body>
</html>
